import { createRouter, createWebHistory } from 'vue-router';
import { stateUrl } from './state';
import { menu } from './menu';
import { useMainStore } from '@/stores';
import { type ActiveMenu } from '@/stores/modules/main';

const router = createRouter({
	history: createWebHistory(import.meta.env.BASE_URL),
	routes: [
		{
			path: '/',
			redirect: '/login'
		},
		...stateUrl,
		{
			path: "/container/:id",
			name: '页面容器',
			component: () => import('@/views/container/index.vue'),
			children: menu
		},
		
	]
})
router.beforeEach((to, from, next) => {
	// console.log(`output->to-from`, to, from)
	next()
})

router.afterEach((to) => {
	const store = useMainStore();
	const title = to.meta?.title as string;
	const obj: ActiveMenu = {
		title,
		path: to.path
	};
	store.setActiveMenu(obj);
	document.title = title;
	window.scrollTo(0, 0);
});
export default router
